/**
 ******************************************************
 * 作者:朱雍
 * 备注:
 * 时间:2017年3月15日上午9:59:11
 * Copyright (c) 2017, 243813208@qq.com All Rights Reserved.
 ******************************************************
 */

package cn.sxt.yxl.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.sxt.yxl.common.controller.BaseController;
import cn.sxt.yxl.common.util.ConstatFinalUtil;
import cn.sxt.yxl.common.util.PageInfoUtil;
import cn.sxt.yxl.question.pojo.AColumns;
import cn.sxt.yxl.question.pojo.AItems;
import cn.sxt.yxl.question.pojo.AItemsEnum;
import cn.sxt.yxl.question.service.IQuestionService;
import sun.util.calendar.BaseCalendar;

/**
 * 类名:IndexController 
 * 备注:	 
 * 时间:2017年3月15日 上午9:59:11
 * 作者:朱雍
 * @since  	JDK 1.8	 
 */
@Controller
public class IndexController extends BaseController{
	@Resource
	private IQuestionService questionService;
	@RequestMapping("/main")
	public String main(HttpServletRequest request){

		return "/head/main";
	}
	
	@RequestMapping("/{url}")
	public String items(@PathVariable String url,HttpServletRequest request){
		//查询url对应的栏目
		Map<String, Object> condMap = new HashMap<>();
		condMap.put("url", url);
		AColumns columns = this.questionService.findOneColumn(condMap);
		request.setAttribute("columns", columns);
		//查询对应栏目的测试项
		condMap.put("status", AItemsEnum.STATUS_ENABLE.getStatus());
		condMap.put("columnsId", columns.getId());
		PageInfoUtil pageInfoUtil = this.pageInfo(request);
		List<AItems> itemsList = this.questionService.findCondItemsList(pageInfoUtil, condMap);
		request.setAttribute("pageInfoUtil", pageInfoUtil);
		request.setAttribute("itemsList", itemsList);
		return "/head/items";
	}
	//测试详情
	@RequestMapping("/items/{iid}")
	public String itemsInfo(@PathVariable int iid,HttpServletRequest request){
		//查询id对应的测试详情
		Map<String, Object> condMap = new HashMap<>();
		condMap.clear();
		condMap.put("id", iid);
		AItems items = this.questionService.findOneItem(condMap);
		condMap.clear();
		request.setAttribute("items", items);
		PageInfoUtil pageInfoUtil = new PageInfoUtil();
		condMap.put("orderBy", "pubTimeASC");
		//上一条
		condMap.put("pubTimeASC", "pubTimeASC");
		condMap.put("pubTimeDa", items.getPubTime());
		List<AItems> preItems = this.questionService.findCondItemsList(pageInfoUtil, condMap);
		request.setAttribute("preItems", preItems);
		condMap.clear();
		//下一条
		condMap.put("pubTimeXiao", items.getPubTime());
		List<AItems> nextItems = this.questionService.findCondItemsList(pageInfoUtil, condMap);
		request.setAttribute("nextItems", nextItems);
		return "/head/itemsInfo";
	}
	
	//问题列表页面
		@RequestMapping("/items/{iid}/start")
		public String questionList(@PathVariable int iid,HttpServletRequest request){
			//查询id对应的测试详情
			Map<String, Object> condMap = new HashMap<>();
			condMap.clear();
			condMap.put("id", iid);
			AItems items = this.questionService.findOneItem(condMap);
			request.setAttribute("items", items);
			return "/head/questionList";
		}
	
	@RequestMapping("/header")
	public String header(HttpServletRequest request){
		
		Map<String, Object> condMap = new HashMap<>();
		condMap.put("status", 1);
		condMap.put("orderBy", "byid");
		List<AColumns> columnsList = this.questionService.findCondColumnsList(null, condMap);
		request.setAttribute("columnsList", columnsList);
		return "/head/header";
	}
	
	@RequestMapping("/test")
	public String test(){
		return "/head/amor";
	}
}

